package com.syc.sqlsession;

import com.syc.config.XMLConfigBuilder;
import com.syc.entity.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * 解析配置文件
 *
 * @author Shen Yu Chen
 * @create 2020-04-23
 **/
public class SqlSessionFactoryBuilder {
    public SqlSessionFactory build(InputStream in) throws PropertyVetoException, DocumentException {

        //第一步: 使用dom4j解析配置文件,封装到配置类中(方便操作)
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.pareConfig(in);

        //第二步：创建sqlSessionFactory工厂, 生产sqlSession:会话对象
        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return sqlSessionFactory;
    }
}
